package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.CreditCardBillTypeEnum;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CreditCardBillEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author xingxing.xiao
 * @date 2020/12/21 15:19
 */
@Getter
public enum TempCreditCardBillDistributorEnum {

    BASE_INFO(CreditCardBillEnum.BASE_INFO),
    CREDIT_CARD_NO(CreditCardBillEnum.CREDIT_CARD_NO),
    TYPE(CreditCardBillEnum.TYPE),
    REF_ID(CreditCardBillEnum.REF_ID),
    AMOUNT(CreditCardBillEnum.AMOUNT),
    SYSTEM_INFO(CreditCardBillEnum.SYSTEM_INFO),
    CREATOR_NAME(CreditCardBillEnum.CREATOR_NAME),
    ADD_TIME(CreditCardBillEnum.ADD_TIME),
    CUSTOMER_ID(CreditCardBillEnum.CUSTOMER_ID),
    CUSTOMER_NAME(CreditCardBillEnum.CUSTOMER_NAME),
    REF_NO(CreditCardBillEnum.REF_NO),
    CREDIT_ID(CreditCardBillEnum.CREDIT_ID),
    BUSINESS_TYPE(CreditCardBillEnum.BUSINESS_TYPE),
    CREATOR_ID(CreditCardBillEnum.CREATOR_ID),
    CREATOR_IS_DISTRIBUTOR(CreditCardBillEnum.CREATOR_IS_DISTRIBUTOR),
    PAYMENT_ORDER_ID(CreditCardBillEnum.PAYMENT_ORDER_ID),
    ;

    private CreditCardBillEnum anEnum;

    TempCreditCardBillDistributorEnum(CreditCardBillEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCreditCardBillDistributorEnum> getAllEnum() {
        List<TempCreditCardBillDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initCreditCardNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.CREDIT_CARD_BILL.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.CREDIT_CARD_BILL.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(CREDIT_CARD_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.CREDIT_CARD_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsDictionary(1);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(CreditCardBillTypeEnum.class, fieldAttrEntity.getFieldType());
        List<String> codeList = Arrays.asList(CreditCardBillTypeEnum.ORDER.getName(), CreditCardBillTypeEnum.PAYMENT_SHEET.getName());
        for (ItemPoJo itemPoJo: itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!codeList.contains(itemPoJo.getText())) {
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            } else {
                if (Objects.equals(itemPoJo.getText(), CreditCardBillTypeEnum.ORDER.getName())) {
                    itemPoJo.setChecked(true);
                }
            }
        }
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias(), ForbiddenSettingEnum.DISABLE_SELF_DEFINE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initCustomerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setLinkedText(CUSTOMER_NAME.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initRefId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setLinkedText(REF_NO.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    /**
     * 不在页面展示
     * @param fieldAttrEntity
     */
    public static void initCreatorName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
